<?php 
namespace User\Controller;
use Think\Model;
class MynotesController extends CommonController{
	
	/**
	 * 个人中心首页
	 */
	public function index(){
		$uid = $_SESSION['loginUser']['uid'];
		$data['artic'] = D('Contents')->where('uid =' .$uid)->select();
		$data['comment'] = D('Comment')->where('uid =' .$uid)->select();
		$data['count']['artic'] = count($data['artic']);
		$data['count']['comment'] = count($data['comment']);
		$this->info = $data;
		$this->display();
				
	}
	
	public function get_artic(){
		$uid = $_SESSION['loginUser']['uid'];
		$p = I('p') ? I('p') : 1;
		$row = I('row') ? I('row') : 10;
		$m = D('Contents');
		$mm = D('Comment');
		$map['uid'] = $uid;
		$map['status'] = '1';
		$result = $m->where($map)->order('update_time DESC')->page($p,$row)->select();
		
		foreach ($result as $key => $value) {
			
			$mmap['sourceTopicId'] = $value['id'];
		    $mmap['status'] = '1';
		    $mmap['replyId'] = 0;
			$value['comment_count'] = $mm->where($mmap)->count();
			$value['update_time']=substr($value['update_time'],0,10);  
			//dump($value);die();
			$data['data'][] = $value;
		}
		
		$data['page']['total'] = $m->where('uid =' .$uid)->count();
		$data['page']['cur'] = $p;
		$data['page']['row'] = $row;
		
		_apiReturn(1,'成功',$data,$url);
	}
	
//	public function get_draft(){
//		$uid = $_SESSION['loginUser']['uid'];
//		$p = I('p') ? I('p') : 1;
//		$row = I('row') ? I('row') : 10;
//		$m = D('Contents');
//		$mm = D('Comment');
//		$map['uid'] = $uid;
//		$map['status'] = '0';
//		$result = $m->where($map)->order('update_time DESC')->page($p,$row)->select();
//		foreach ($result as $key => $value) {
//			$mmap['sourceTopicId'] = $value['id'];
//		    $mmap['status'] = '1';
//		    $mmap['replyId'] = 0;
//			$value['comment_count'] = $mm->where($mmap)->count();
//			$data['data'][] = $value;
//		}
//		
//		$data['page']['total'] = $m->where('uid =' .$uid)->count();
//		$data['page']['cur'] = $p;
//		$data['page']['row'] = $row;
//		
//		_apiReturn(1,'成功',$data,$url);
//	}
//	
//	public function get_comment(){
//		$uid = I('uid') ? I('uid') : $_SESSION['loginUser']['uid'];
//		if(!$uid)
//			_apiReturn(0,"请先登录");
//		$p = I('p') ? I('p') : 1;
//		$row = I('row') ? I('row') : 10;
//		$m = D('Comment');
//		$mm = D('Contents');
//		$result = $m->where('uid =' .$uid)->order('ctime DESC')->page($p,$row)->select();
//		foreach ($result as $key => $value) {
//			$value['content_id'] = $value['sourcetopicid'];
//			$value['content_title'] = $mm->where('id =' .$value['content_id'])->getField('title');
//			$data['data'][] = $value;
//		}
////		for($k=0;$k<count($data['data']);$k++){
////			$data['data'][$k]['content_id'] = substr($data['data'][$k]['sourcetopicid'],8);
////			$data['data'][$k]['content_title'] = D('Contents')->where('id =' .$data['data'][$k]['content_id'])->getField('title');
////		}
//		$data['page']['total'] = $m->where('uid =' .$uid)->count();
//		$data['page']['cur'] = $p;
//		$data['page']['row'] = $row;
//		
//		_apiReturn(1,'成功',$data,$url);
//	}
//	
//	public function get_mess(){
//		$uid = $_SESSION['loginUser']['uid'];
//		$p = I('p') ? I('p') : 1;
//		$row = I('row') ? I('row') : 10;	
//		$sql = "SELECT A.`title`,A.`id`,B.`nickname`,B.`content`,B.`ctime`,C.`avater`,C.`uid` FROM mini_contents A JOIN mini_comment B ON A.`id`=B.`sourceTopicId` JOIN mini_users C ON B.`uid`=C.`uid` WHERE A.`uid`=".$uid." order by B.ctime desc";
//		$sqlcount = "SELECT count(DISTINCT B.`id`) AS total_count FROM mini_contents A JOIN mini_comment B ON A.`id`=B.`sourceTopicId` JOIN mini_users C ON B.`uid`=C.`uid` WHERE A.`uid`=".$uid."";
//		$sql .= ' limit '.($p-1)*$row.','.$row;
//		$model = new Model();
//		$data['data'] = $model->query($sql);
//		$count = $model->query($sqlcount);
//		$data['page']['total'] = $count[0]['total_count'];
//		$data['page']['cur'] = $p;
//		$data['page']['row'] = $row;
//		
//		_apiReturn(1,'成功',$data,$url);
//	}
//	
//	public function get_at(){
//		$username = $_SESSION['loginUser']['username'];
//		$p = I('p') ? I('p') : 1;
//		$row = I('row') ? I('row') : 10;	
//		$sql = "SELECT A.`content`,A.`nickname`,A.`ctime`,B.`id`,B.`title`,C.`avater`,C.`uid` FROM mini_comment A JOIN mini_contents B ON A.`sourceTopicId`=B.`id` JOIN mini_users C ON A.uid=C.`uid` WHERE A.`content` LIKE '%@".$username." %' order by A.ctime desc ";
//		$sqlcount = "SELECT count(DISTINCT A.`id`) AS total_count FROM mini_comment A JOIN mini_contents B ON A.`sourceTopicId`=B.`id` JOIN mini_users C ON A.uid=C.`uid` WHERE A.`content` LIKE '%@".$username." %'";
//		$sql .= ' limit '.($p-1)*$row.','.$row;
//		$model = new Model();
//		$data['data'] = $model->query($sql);
//		$count = $model->query($sqlcount);
//		$data['page']['total'] = $count[0]['total_count'];
//		$data['page']['cur'] = $p;
//		$data['page']['row'] = $row;
//		
//		_apiReturn(1,'成功',$data,$url);
//	}
//	
//	public function get_collect(){
//		$map['uid'] = $_SESSION['loginUser']['uid'];
//		$p = I('p') ? I('p') : 1;
//		$row = I('row') ? I('row') : 10;
//		$m = D('Collect');
//		$mm = D('Contents');
//		$result = $m->where($map)->select();
//		
//		foreach ($result as $key => $value) {
//			$value['title'] = $mm->where('id =' .$value['cid'])->page($p,$row)->getField('title');
//			$data['data'][] = $value;
//		}
//		
//		$data['page']['total'] = $m->where($map)->count();
//		$data['page']['cur'] = $p;
//		$data['page']['row'] = $row;
//		_apiReturn(1,'成功',$data,$url);
//	}
	
	public function get_uid(){
		$name = I('name');
		$m = D('Users');
		$uid = $m ->where('username =' .$name)->getField('uid');
		_apiReturn(1,'成功',$uid,$url);
	}
	
	
	
}
?>